package formin.powerbar.core;
import java.util.Calendar;
import java.util.Date;

public class PowerBarTimeService {
	private Calendar cal; 
	private Date date;
	
	
	public PowerBarTimeService(){
		cal = Calendar.getInstance();	
	}
	
	
	//returns the current time in minutes. 0 for midnight, (12*60)=720 for noon etc.
	// minvalue returned 0 , maxvalue returned (24*60)-1 = 1439
	public int getCurrentTime(){
		date = cal.getTime();
		return ((date.getHours()*60) + date.getMinutes());
	}
	public int getCurrent24Hour(){
		return cal.getTime().getHours();
	}
	public int getCurrent12Hour(){
		return (cal.getTime().getHours()%12);
	}
	public int getCurrentMinutes(){
		return cal.getTime().getMinutes();
	}
	
	
	//time utilities that act on the total number of minutes
	public int get24HoursFrom(int time){
		return time / 60;
	}
	public int get12HoursFrom(int time){
		int t = (time / 60) % 12;
		if (t==0){
			return 12;
		}
		return t;
	}
	public int getMinutesFrom(int time){
		return time % 60;
	}
	public boolean isAMFrom(int time){
		if (time >= 720){
			return false;
		}
		return true;
	}
}
